

package com.jysz.certificate.persistence.model.system;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import com.jysz.webcore.ssh.entity.AbstractBaseEntity;

/**
 * 负责发号处理的表格，此表记录了所有发号的表的内容.
 * 
 * @author <a href="mailto:javaengine@outlook.com">Kaca Rich</a>
 *
 */
@Entity
@Table(name = "sys_sequence_number_")
@org.hibernate.annotations.Entity
public class SequenceNumber extends AbstractBaseEntity<Long> {
	/**
	 * 
	 */
	private static final long serialVersionUID = -8191939241581258775L;
	
	/**
	 * 发号类型
	 * 
	 * @author <a href="mailto:javaengine@outlook.com">Kaca Rich</a>
	 *
	 */
	public enum SequenceType {
		/**
		 * 序号
		 */
		序号,
		
		/**
		 * 规则码
		 */
		规则码
	}
	
	/**
	 * 是否显示格式    
 	 *  1是显示 0是不显示
	 * 对序号进行格式化的字符串
	 * 
	 */
	private String isDisplayStyle;
	
	/**
	 * 当前序号值
	 */
	private int currentNum;
	
	/**
	 * 序号的步长
	 */
	private int stepNum;

	/**
	 * 实体的类名
	 */
	private String entityClazzName;

	/**
	 * 序号的类型
	 * 
	 */
	private SequenceType seqType;

	/**
	 * 序号格式化字符串
	 * 
	 */
	private String seqFormat;

	/**
	 * 序号的长度限制
	 */
	private int lengthLimited;
	
	/**
	 * 该记录的版本
	 */
	private int version;

	
	@Column(name = "_current_num",columnDefinition="int(11)")
	public int getCurrentNum() {
		return this.currentNum;
	}

	/**
	 * @param currentNum The currentNum to set.
	 */
	public void setCurrentNum(int currentNum) {
		this.currentNum = currentNum;
	}

	@Column(name="_entity_clazz_name", length=100,columnDefinition="varchar(100)")
	public String getEntityClazzName() {
		return this.entityClazzName;
	}

	/**
	 * @param entityClazzName The entityClazzName to set.
	 */
	public void setEntityClazzName(String entityClazzName) {
		this.entityClazzName = entityClazzName;
	}
	
	@Column(name="_length_limited",columnDefinition="int(11)")
	public int getLengthLimited() {
		return this.lengthLimited;
	}

	public void setLengthLimited(int lengthLimited) {
		this.lengthLimited = lengthLimited;
	}

	@Column(name="_seq_format", length = 100,columnDefinition="varchar(100)")
	public String getSeqFormat() {
		return this.seqFormat;
	}

	public void setSeqFormat(String seqFormat) {
		this.seqFormat = seqFormat;
	}
	
	@Column(name="_seq_type", length = 10,columnDefinition="int(11)")
	public SequenceType getSeqType() {
		return this.seqType;
	}

	public void setSeqType(SequenceType seqType) {
		this.seqType = seqType;
	}

	@Column(name="_step_num",columnDefinition="int(11)")
	public int getStepNum() {
		return this.stepNum;
	}

	public void setStepNum(int stepNum) {
		this.stepNum = stepNum;
	}

	/**
	 * 得到当前格式化后的字符串.
	 * @param otherFormatObjs  其他的格式化参数
	 * @return 返回格式化后的字符串。
	 */
	public String getSeqNumFormatted(Object ... otherFormatObjs) {
		if(this.getSeqFormat()==null){
			return Integer.toString(this.getCurrentNum());
		}
		
		List<Object> list=new ArrayList<Object>();
		list.addAll(Arrays.asList(otherFormatObjs));
		list.add(0,this.getCurrentNum());
		
		return String.format(this.getSeqFormat(),list.toArray());	
	}

	@Column(name="_lock_version",columnDefinition="int(11)")
	public int getVersion() {
		return this.version;
	}

	public void setVersion(int version) {
		this.version = version;
	}

	@Column(name = "_is_display_style", length= 2,columnDefinition="varchar(2)")
	public String getIsDisplayStyle() {  
		return isDisplayStyle;
	}

	public void setIsDisplayStyle(String isDisplayStyle) {
		this.isDisplayStyle = isDisplayStyle;    
	}
	
    /* bean properties begin */
    public static final String IS_DISPLAY_STYLE_PRO_NAME="isDisplayStyle";
    public static final String CURRENT_NUM_PRO_NAME="currentNum";
    public static final String STEP_NUM_PRO_NAME="stepNum";
    public static final String ENTITY_CLAZZ_NAME_PRO_NAME="entityClazzName";
    public static final String SEQ_TYPE_PRO_NAME="seqType";
    public static final String SEQ_FORMAT_PRO_NAME="seqFormat";
    public static final String LENGTH_LIMITED_PRO_NAME="lengthLimited";
    public static final String VERSION_PRO_NAME="version";
    /* bean properties end */
}